###################################################################
# Author: Mu yanru
# Date  : 2019.2
# Email : muyanru345@163.com
###################################################################

# Import future modules
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# Import third-party modules
from PySide2.QtWidgets import QHBoxLayout, QVBoxLayout, QGridLayout
from Qt import QtCore
from Qt import QtWidgets

# Import local modules
from dayu_widgets.divider import MDivider
from dayu_widgets.field_mixin import MFieldMixin
from dayu_widgets.label import MLabel
from dayu_widgets.push_button import MPushButton
from dayu_widgets import dayu_theme, MFlowLayout, MMeta
from dayu_widgets.qt import MPixmap


class HomeTab(QtWidgets.QWidget, MFieldMixin):
    def __init__(self, parent=None):
        super(HomeTab, self).__init__(parent)
        self._init_ui()

    def _init_ui(self):
        title_label = MLabel("欢迎使用红尘分析系统").h1()
        title_lay = QHBoxLayout()
        title_lay.addWidget(title_label)
        title_lay.setAlignment(QtCore.Qt.AlignHCenter)

        meta_card_lay = QHBoxLayout()
        meta_card_lay.setSpacing(50)
        meta_array = [{
            "title": "参考文档",
            "description": "大数据分析工具旗舰产品",
            "cover": MPixmap("app-maya.png"),
        },
            {
                "title": "项目管理",
                "description": "3D 数字动画和视觉效果的世界领先软件应用程序",
                "cover": MPixmap("app-maya.png"),
            }, {
                "title": "函数管理",
                "description": "3D 数字动画和视觉效果的世界领先软件应用程序",
                "cover": MPixmap("app-maya.png"),
            }, {
                "title": "数据源管理",
                "description": "3D 数字动画和视觉效果的世界领先软件应用程序",
                "cover": MPixmap("app-maya.png"),
            },
        ]
        meta_card_lay.addStretch(1)
        for meta in meta_array:
            meta_card = MMeta()
            meta_card.setup_data(meta)
            meta_card_lay.addWidget(meta_card)
        meta_card_lay.addStretch(1)
        meta_card_lay.setAlignment(QtCore.Qt.AlignCenter)

        main_lay = QVBoxLayout()
        main_lay.addLayout(title_lay, 1)
        main_lay.addLayout(meta_card_lay, 1)
        main_lay.addStretch(3)
        self.setLayout(main_lay)


    def slot_change_text(self):
        # Import built-in modules
        import random

        self.set_field("show_text", random.choice(["Dog", "Cat", "Rabbit", "Cow"]))

    def slot_link_text(self):
        self.set_field("is_link", not self.field("is_link"))


if __name__ == "__main__":
    # Import local modules
    from dayu_widgets import dayu_theme, MFlowLayout, MMeta
    from dayu_widgets.qt import application, MPixmap

    with application() as app:
        test = HomeTab()
        dayu_theme.apply(test)
        test.show()
